Repository navigation
Conversation
ordinal() computed the suffix from value % 10 and value % 100, but Python's modulo on a negative number gave the wrong digit, so e.g. ordinal(-9) was "-9st" and ordinal(-1) was "-1th". Use the magnitude instead.
|
Please see questions on duplicate #321. |
|
I think the framing on #321 was "do negative ordinals make sense," but that's not quite what this fixes. ordinal() already accepts negative ints today — it doesn't raise — it just returns grammatically impossible strings: ordinal(-9) gives -9st, ordinal(-21) gives -21th. So the choice isn't "support negatives or not," it's "keep emitting broken output, or fix it." If you'd genuinely rather not handle negatives, I'd argue raising or returning the value unchanged is cleaner than returning -9st. But given it already accepts them, correcting the suffix seemed like the least surprising option. Happy to close if you feel strongly it's out of scope |
|
The framing on #321 was "do negative ordinals make sense," but that's not quite what this fixes. |
|
Please don't let your LLM spam the same answer twice. |
|
Sorry — that was a duplicate from a tooling mistake on my end, not intentional. Won't happen again. |
There was a problem hiding this comment.
Independent sign-symmetry check passed for every n=1–1000: ordinal(-n) == "-" + ordinal(n). This includes repeated 11/12/13 exceptions across hundreds and covers far more negative endings than the added examples. Using the magnitude for suffix selection preserves the sign in the rendered number while applying the same suffix rule as positive ordinals. I ran these checks on Python 3.12 with English locale hooks; no full localization or pytest run.
Calling
ordinal()on a negative integer gives the wrong suffix:The suffix is chosen from
value % 10andvalue % 100, but Python's modulo of a negative number counts up from the next lower multiple (-9 % 10 == 1,-1 % 10 == 9), so the digit used for the lookup is wrong for every negative value.Computing the digit from
abs(value)fixes it while leaving non-negative values, the 11/12/13 special case, and the non-finite / non-numeric paths unchanged:Added the negative cases to
test_ordinal; the fulltest_number.pysuite passes.